<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const HOST = Symbol('host'); // 属性保护 只能在类及子类中使用
        class User {
            [HOST]="https://baidu.com";
            constructor(name) {
                this.name = name;
            }
            set host(url){
                if(!/^https?:/i.test(url)){
                    throw new Error('非法地址')
                }
                this[HOST] = url;
            }
            get host(){
                return this[HOST];
            }
        }
        
        let zh = new User('张三')
        console.log(zh)
        zh.host = 'https://haha.com';
        console.log(zh)
    </script>
</body>

</html>